use Mojo::DOM;
use POE;

{
	irc_on_anymsg => sub {
		BotIrc::check_ctx() or return;

		if ($_[ARG2] =~ m#\b(https?://\S+)#i) {
			my $url = $1;
			my $ctx = BotIrc::ctx_frozen;
			BotHttp::get($url, sub {
				my $dom;
				eval {
					$dom = Mojo::DOM->new(shift);
				};
				return if $@;
				my $node = $dom->at('head title');
				return if !$node;
				BotIrc::send_wisdom($ctx, "Title: ". $node->all_text);
			}, sub {});
		}
	},
};
